<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商户编号" prop="merchantNo">
        <el-select v-model="queryParams.merchantNo" placeholder="请选择商户编号" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="法人姓名" prop="artificialPersonName">
        <el-input
          v-model="queryParams.artificialPersonName"
          placeholder="请输入法人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人联系方式" prop="artificialPersonConcat">
        <el-input
          v-model="queryParams.artificialPersonConcat"
          placeholder="请输入法人联系方式"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人身份证号" prop="artificialPersonIdNo">
        <el-input
          v-model="queryParams.artificialPersonIdNo"
          placeholder="请输入法人身份证号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证正面" prop="idCardFront">
        <el-input
          v-model="queryParams.idCardFront"
          placeholder="请输入身份证正面"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证背面" prop="idCardBack">
        <el-input
          v-model="queryParams.idCardBack"
          placeholder="请输入身份证背面"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人名称" prop="contactName">
        <el-input
          v-model="queryParams.contactName"
          placeholder="请输入联系人名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人手机" prop="contactMobile">
        <el-input
          v-model="queryParams.contactMobile"
          placeholder="请输入联系人手机"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人座机" prop="contactTelephone">
        <el-input
          v-model="queryParams.contactTelephone"
          placeholder="请输入联系人座机"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮编" prop="post">
        <el-input
          v-model="queryParams.post"
          placeholder="请输入邮编"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核编号" prop="examineCode">
        <el-input
          v-model="queryParams.examineCode"
          placeholder="请输入审核编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人" prop="buildOperator">
        <el-input
          v-model="queryParams.buildOperator"
          placeholder="请输入创建人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建日期" prop="buildDate">
        <el-input
          v-model="queryParams.buildDate"
          placeholder="请输入创建日期"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="buildTime">
        <el-input
          v-model="queryParams.buildTime"
          placeholder="请输入创建时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改人" prop="modifiedOperator">
        <el-input
          v-model="queryParams.modifiedOperator"
          placeholder="请输入修改人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改日期" prop="modifiedDate">
        <el-input
          v-model="queryParams.modifiedDate"
          placeholder="请输入修改日期"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改时间" prop="modifiedTime">
        <el-input
          v-model="queryParams.modifiedTime"
          placeholder="请输入修改时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['merchant:contact:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['merchant:contact:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['merchant:contact:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['merchant:contact:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="contactList" @selection-change="handleSelectionChange" :border="true">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="商户编号" align="center" prop="merchantNo" />
      <el-table-column label="法人姓名" align="center" prop="artificialPersonName" />
      <el-table-column label="法人联系方式" align="center" prop="artificialPersonConcat" />
      <el-table-column label="法人身份证号" align="center" prop="artificialPersonIdNo" />
      <el-table-column label="身份证正面" align="center" prop="idCardFront" />
      <el-table-column label="身份证背面" align="center" prop="idCardBack" />
      <el-table-column label="联系人名称" align="center" prop="contactName" />
      <el-table-column label="联系人手机" align="center" prop="contactMobile" />
      <el-table-column label="联系人座机" align="center" prop="contactTelephone" />
      <el-table-column label="地址" align="center" prop="address" />
      <el-table-column label="邮编" align="center" prop="post" />
      <el-table-column label="审核编号" align="center" prop="examineCode" />
      <el-table-column label="创建人" align="center" prop="buildOperator" />
      <el-table-column label="创建日期" align="center" prop="buildDate" />
      <el-table-column label="创建时间" align="center" prop="buildTime" />
      <el-table-column label="修改人" align="center" prop="modifiedOperator" />
      <el-table-column label="修改日期" align="center" prop="modifiedDate" />
      <el-table-column label="修改时间" align="center" prop="modifiedTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['merchant:contact:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['merchant:contact:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商户联系人对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商户编号" prop="merchantNo">
          <el-select v-model="form.merchantNo" placeholder="请选择商户编号">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="法人姓名" prop="artificialPersonName">
          <el-input v-model="form.artificialPersonName" placeholder="请输入法人姓名" />
        </el-form-item>
        <el-form-item label="法人联系方式" prop="artificialPersonConcat">
          <el-input v-model="form.artificialPersonConcat" placeholder="请输入法人联系方式" />
        </el-form-item>
        <el-form-item label="法人身份证号" prop="artificialPersonIdNo">
          <el-input v-model="form.artificialPersonIdNo" placeholder="请输入法人身份证号" />
        </el-form-item>
        <el-form-item label="身份证正面" prop="idCardFront">
          <el-input v-model="form.idCardFront" placeholder="请输入身份证正面" />
        </el-form-item>
        <el-form-item label="身份证背面" prop="idCardBack">
          <el-input v-model="form.idCardBack" placeholder="请输入身份证背面" />
        </el-form-item>
        <el-form-item label="联系人名称" prop="contactName">
          <el-input v-model="form.contactName" placeholder="请输入联系人名称" />
        </el-form-item>
        <el-form-item label="联系人手机" prop="contactMobile">
          <el-input v-model="form.contactMobile" placeholder="请输入联系人手机" />
        </el-form-item>
        <el-form-item label="联系人座机" prop="contactTelephone">
          <el-input v-model="form.contactTelephone" placeholder="请输入联系人座机" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="邮编" prop="post">
          <el-input v-model="form.post" placeholder="请输入邮编" />
        </el-form-item>
        <el-form-item label="审核编号" prop="examineCode">
          <el-input v-model="form.examineCode" placeholder="请输入审核编号" />
        </el-form-item>
        <el-form-item label="创建人" prop="buildOperator">
          <el-input v-model="form.buildOperator" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建日期" prop="buildDate">
          <el-input v-model="form.buildDate" placeholder="请输入创建日期" />
        </el-form-item>
        <el-form-item label="创建时间" prop="buildTime">
          <el-input v-model="form.buildTime" placeholder="请输入创建时间" />
        </el-form-item>
        <el-form-item label="修改人" prop="modifiedOperator">
          <el-input v-model="form.modifiedOperator" placeholder="请输入修改人" />
        </el-form-item>
        <el-form-item label="修改日期" prop="modifiedDate">
          <el-input v-model="form.modifiedDate" placeholder="请输入修改日期" />
        </el-form-item>
        <el-form-item label="修改时间" prop="modifiedTime">
          <el-input v-model="form.modifiedTime" placeholder="请输入修改时间" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listContact, getContact, delContact, addContact, updateContact, exportContact } from "@/api/merchant/contact";

export default {
  name: "Contact",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商户联系人表格数据
      contactList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        merchantNo: null,
        artificialPersonName: null,
        artificialPersonConcat: null,
        artificialPersonIdNo: null,
        idCardFront: null,
        idCardBack: null,
        contactName: null,
        contactMobile: null,
        contactTelephone: null,
        address: null,
        post: null,
        examineCode: null,
        buildOperator: null,
        buildDate: null,
        buildTime: null,
        modifiedOperator: null,
        modifiedDate: null,
        modifiedTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商户联系人列表 */
    getList() {
      this.loading = true;
      listContact(this.queryParams).then(response => {
        this.contactList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        merchantNo: null,
        artificialPersonName: null,
        artificialPersonConcat: null,
        artificialPersonIdNo: null,
        idCardFront: null,
        idCardBack: null,
        contactName: null,
        contactMobile: null,
        contactTelephone: null,
        address: null,
        post: null,
        examineCode: null,
        buildOperator: null,
        buildDate: null,
        buildTime: null,
        modifiedOperator: null,
        modifiedDate: null,
        modifiedTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商户联系人";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getContact(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商户联系人";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateContact(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addContact(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除商户联系人编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delContact(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有商户联系人数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportContact(queryParams);
        }).catch(() => {});
    }
  }
};
</script>
